<html>
<head>
    <script type="text/javascript" src="../libjs/Perl6/MetaModel.js"></script>
    <script type="text/javascript">
        require.INC = "../inc";    
        require('Test.Builder');
        require('Test.More');        
    
        require.INC = "../libjs";    
        require('Perl6.MetaClass');
        require('Perl6.Method');        
    </script>     
</head>
<body>
<pre id='test'><script type="text/javascript">

plan({ tests : 25 });

var m1 = new Perl6.MetaClass('Dog', '0.0.1', 'jsan:STEVAN');
isaOK(m1, 'Perl6.MetaClass');

is(m1.name(), 'Dog', '... got the right name');
is(m1.version(), '0.0.1', '... got the right version');
is(m1.authority(), 'jsan:STEVAN', '... got the right authority');

is(m1.identifier(), 'Dog-0.0.1-jsan:STEVAN', '... got the right identifier');

ok(m1.is_a('Dog'), '... this metaclass isa Dog');
ok(!m1.is_a('Fido'), '... this metaclass is not a Fido');

isDeeply(m1.MRO(), [m1], '... got the right MRO for m1');

var method1 = new Perl6.Method(m1, function () { 'Dog::bark' });
isaOK(method1, 'Perl6.Method');

m1.add_method('bark', method1);

ok(m1.has_method('bark'), '... the method bark() can be found');
is(m1.get_method('bark'), method1, '... the method bark() has been added successfully')

ok(!m1.has_method('bark', 'class'), '... the method bark() cannot be found in class');

var method2 = new Perl6.Method(m1, function () { 'Dog::growl' });
isaOK(method2, 'Perl6.Method');

m1.add_method('growl', method2, 'class');

ok(m1.has_method('growl', 'class'), '... the method growl() can be found');
is(m1.get_method('growl', 'class'), method2, '... the method growl() has been added successfully')

ok(!m1.has_method('growl'), '... the method growl() cannot be found in instance');

// ... 

var m2 = new Perl6.MetaClass('Fido', '0.0.1');
isaOK(m2, 'Perl6.MetaClass');

is(m2.name(), 'Fido', '... got the right name');
is(m2.version(), '0.0.1', '... got the right version');
is(m2.authority(), false, '... got the right authority');

is(m2.identifier(), 'Fido-0.0.1', '... got the right identifier');

m2.superclasses([ m1 ]);

is(m2.superclasses()[0], m1, '... our superclass is as expected');

ok(m2.is_a('Dog'), '... this metaclass isa Dog');
ok(m2.is_a('Fido'), '... this metaclass isa Fido');

isDeeply(m2.MRO(), [ m2, m1 ], '... got the right MRO for m2');

</script></pre>
</body>
</html>
